package com.zf.museum.controller;



import com.zf.museum.bean.Question;
import com.zf.museum.bean.Result;
import com.zf.museum.model.Tfng;
import com.zf.museum.service.TfngService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description = "判断题")
@RestController
@RequestMapping("/tfng")
public class TfngController {

   @Autowired
   private TfngService tfngService;

   @ApiOperation(value = "上传题目", notes = "上传含有Excel表格的题目")
   @PostMapping("/upload")
   @RequiresRoles("admin")
   public Result upload(MultipartFile file) {

      return tfngService.upload(file);
   }

   @ApiOperation(value = "查看所有题目")
   @GetMapping("/findAll")
   @RequiresRoles("admin")
   public List<Tfng> findAll() {

      return tfngService.findAll();
   }

   @ApiOperation(value = "修改题目内容", notes = "返回修改后的所有题目")
   @ApiImplicitParam(name = "tfngs", value = "题目的集合", dataType = "Tfng")
   @PostMapping("/update")
   @RequiresRoles("admin")
   public Result update(@RequestBody List<Tfng> tfngs) {
      return tfngService.update(tfngs);
   }

   @ApiOperation(value = "删除题目", notes = "返回删除的题数")
   @ApiImplicitParam(name = "ids", value = "题目id的集合", dataType = "Array[long]")
   @PostMapping("/delete")
   @RequiresRoles("admin")
   public Result delete(@RequestBody List<Long> ids) {

      return tfngService.delete(ids);
   }

   @ApiOperation(value = "获取6道题目")
   @GetMapping("/getTfngs")
   public List<Tfng> getTfngs(@RequestParam("openId") String openId) {

      return tfngService.getTfngs(openId);
   }


}
